﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'laydate', 'common', 'xmSelect', 'optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common;
        var keyValue = $.request("keyValue");
        var keyData = {};
        $(function () {
            if (!!keyValue) {
                var tempdata = common.currentWindow().layui.table.cache.currentTableId;
                for (var i = 0; i < tempdata.length; i++) {
                    if (keyValue == tempdata[i].F_Id) {
                        keyData = tempdata[i];
                        common.val('adminform', tempdata[i]);
                        break;
                    }
                }
                form.render();
            }
        });
        wcLoading.close();
        //监听提交
        var lock = false;
        form.on('submit(saveBtn)', function (data) {
            if (!lock) {
                var postData = data.field;
                if (parseFloat(postData.F_PlanNum) <= parseFloat(postData.F_SplitNum) * parseInt(postData.F_NoteNum)) {
                    common.modalMsg("分割总数不能大于本单", "warning");
                    return false;
                }
                var index = parent.layer.load(0, {
                    shade: [0.5, '#000'], //0.1透明度的背景
                });
                lock = true;
                var tempdata = common.currentWindow().layui.table.cache.currentTableId;
                for (var i = 0; i < tempdata.length; i++) {
                    if (keyData.F_Id == tempdata[i].F_Id) {
                        tempdata[i].F_PlanNum = parseFloat(postData.F_PlanNum) - parseFloat(postData.F_SplitNum) * parseInt(postData.F_NoteNum);
                        tempdata[i].LAY_CHECKED = false;
                        break;
                    }
                }
                for (var i = 0; i < postData.F_NoteNum; i++) {
                    var temp = {};
                    temp.F_MaterialId = keyData.F_MaterialId;
                    temp.F_BadNum = keyData.F_BadNum;
                    temp.F_DeleteMark = keyData.F_DeleteMark;
                    temp.F_DoneNum = keyData.F_DoneNum;
                    temp.F_EnabledMark = keyData.F_EnabledMark;
                    temp.F_MaterialCode = keyData.F_MaterialCode;
                    temp.F_MaterialName = keyData.F_MaterialName;
                    temp.F_MaterialType = keyData.F_MaterialType;
                    temp.F_MaterialUnit = keyData.F_MaterialUnit;
                    temp.F_ProcessId = keyData.F_ProcessId;
                    temp.F_ProcessName = keyData.F_ProcessName;
                    temp.F_RunSort = keyData.F_RunSort;
                    temp.F_Id = uuid();
                    temp.F_PlanNum = postData.F_SplitNum;
                    temp.F_Description = postData.F_Description;
                    tempdata.push(temp);
                }
                tempdata.sort(function (a, b) { return a.F_RunSort - b.F_RunSort });
                common.modalMsg("操作成功", "success");
                common.currentWindow().layui.table.reload('currentTableId', {
                    data: tempdata
                });
                parent.layer.close(index);
                common.modalClose();
                lock = false;
            }
            return false;
        });
    });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item">
                    <label class="layui-form-label">物料编号</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_MaterialCode" disabled="disabled" name="F_MaterialCode" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">物料名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_MaterialName" disabled="disabled" name="F_MaterialName" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">数量</label>
                    <div class="layui-input-block">
                        <input type="number" pattern="[0-9]*" id="F_PlanNum" name="F_PlanNum" disabled="disabled" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">拆分单数</label>
                    <div class="layui-input-block">
                        <input type="number" pattern="[0-9]*" id="F_NoteNum" name="F_NoteNum" value="1" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">每单数量</label>
                    <div class="layui-input-block">
                        <input type="number" pattern="[0-9]*" id="F_SplitNum" name="F_SplitNum" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="F_Description" name="F_Description" class="layui-textarea" placeholder="请输入备注"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>

